﻿
@{
    Layout = null;
}

<head>
    <meta name="viewport" content="width=device-width" />
    <title>登录-文件浏览系统</title>
    <script src="~/Scripts/jquery-3.4.1.min.js"></script>
    <link href="~/Content/layui-v2.8.15/layui/css/layui.css" rel="stylesheet" />
    <script src="~/Content/layui-v2.8.15/layui/layui.js"></script>
    <script src="~/Content/layui-v2.8.15/layui/axios.min.js"></script>
</head>


<style>
    .demo-login-container {
        width: 320px;
        position: absolute;
        /*居中显示*/
        top: 28%;
        bottom: 0;
        left: 0;
        right: 0;
        margin: auto;
    }

    .demo-login-other .layui-icon {
        position: relative;
        display: inline-block;
        margin: 0 2px;
        top: 2px;
        font-size: 26px;
    }
</style>

<form class="layui-form">

    <div class="demo-login-container box">
        <h1 style="text-align:center;margin-bottom:30px;">文件浏览系统</h1>
        <div class="layui-form-item">
            <div class="layui-input-wrap">
                <div class="layui-input-prefix">
                    <i class="layui-icon layui-icon-username"></i>
                </div>
                <input type="text" id="account" name="username" value="admin" lay-verify="required" placeholder="用户名" lay-reqtext="请填写用户名" autocomplete="off" class="layui-input" lay-affix="clear">
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-wrap">
                <div class="layui-input-prefix">
                    <i class="layui-icon layui-icon-password"></i>
                </div>
                <input type="password" id="password" name="password" value="" lay-verify="required" placeholder="密   码" lay-reqtext="请填写密码" autocomplete="off" class="layui-input" lay-affix="eye">
            </div>
        </div>


        <div class="layui-form-item">
            <button class="layui-btn layui-btn-fluid" lay-submit lay-filter="demo-login">登录</button>

        </div>
        <div class="layui-form-item">
            <button class="layui-btn layui-btn-fluid" type="button" onclick="DoRegister()">注册</button>

        </div>

    </div>
</form>

<script>
    layui.use(function () {
        var form = layui.form;
        var layer = layui.layer;
        // 提交事件
        form.on('submit(demo-login)', function (data) {
            var field = data.field; // 获取表单字段值
            $.ajax({
                url: "/LoginHandle/DoLogin",
                type: "post",
                data: {
                    account: field.username,
                    pwd: field.password,
                },
                success: function (r) {
                    if (r.Code == 200) {
                        localStorage.setItem('jwtToken', r.Msg);
                        layer.msg("登陆成功");
                        window.location.href = "/home/index";
                    }
                    else {
                        layer.msg(r.Msg);
                    }

                }
            });
            return false;
        });

    });
    async function DoRegister() {
        var field = {
            username: $('#account').val(),
            password: $('#password').val()
        };
        try {
            let response = await axios.post('/LoginHandle/DoRegister', { account: field.username, pwd: field.password });
            if (response != null) {
                if (response.data.Code == 500) {
                    layer.msg(response.data.Msg);
                } else if (response.data.Code == 200) {
                    layer.msg(response.data.Msg);
                }
            }
        } catch (error) {
            console.error(error);
        }
        return false;
    };
</script>



